package com.ang.hutool.random;

import cn.hutool.core.util.RandomUtil;

import java.util.stream.IntStream;

/**
 * @author ssang
 * @date 2022-01-20 10:30
 */
public class RandomPassword {
    public static void main(String[] args) {
//        System.out.println(RandomUtil.randomString(RandomUtil.BASE_CHAR,5));
//        System.out.println(RandomUtil.randomString(RandomUtil.BASE_CHAR_NUMBER,5));
//        System.out.println(RandomUtil.randomString("!@#$%_+=*",5));
//        System.out.println(RandomUtil.randomInt(3));
//        System.out.println(RandomUtil.randomString(1));
//        System.out.println(RandomUtil.randomStringUpper(1));
        buildPassword(16);
    }

    public static void buildPassword(int length){
        StringBuffer password1 = new StringBuffer();
        IntStream.range(0,length).forEach(i->{
            password1.append(getRandomChar1());
        });

        StringBuffer password2 = new StringBuffer();
        IntStream.range(0,length).forEach(i->{
            password2.append(getRandomChar2());
        });

        System.out.println(password1.toString());
        System.out.println(password2.toString());
    }

    public static String getRandomChar1(){
        int i = RandomUtil.randomInt(10);
        String res;

        if(i%2 == 0){
            if(i>2){
                res = RandomUtil.randomString(1);
            }else{
                res = RandomUtil.randomStringUpper(1);
            }
        }else{
            if(i>1){
                res = String.valueOf(RandomUtil.randomInt(10));
            }else{
                res = RandomUtil.randomString("!@#$%_+=*",1);
            }
        }

        return res;
    }

    public static String getRandomChar2(){
        int i = RandomUtil.randomInt(10);
        String res;

        if(i%2 == 0){
            if(i>2){
                res = RandomUtil.randomString(1);
            }else{
                res = RandomUtil.randomStringUpper(1);
            }
        }else{
            if(i>1){
                res = String.valueOf(RandomUtil.randomInt(10));
            }else{
                res = RandomUtil.randomString("!@#$%_+=*",1);
            }
        }

        return res;
    }
}
